package fr.ul.ade.prime.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * @author Schnell Michaël
 * @version 1.0
 */
public enum ScheduleState implements Parcelable {

	OTHER(100), // State unknown

	WAITING_FOR_UPDATE(100), // Update schedule, waiting

	UPDATING_STEP_1( 5), // 5 - Connected to ADE
	UPDATING_STEP_2(10), // 5 - Project set
	UPDATING_STEP_3(55), // 45 - Lessons feed obtained
	UPDATING_STEP_4(65), // 10 - Lessons feed analyzed
	UPDATING_STEP_5(80), // 15 - Compared with previous schedule
	UPDATING_STEP_6(90), // 20 Schedule updated

	NOT_UPDATED(100), // Last update was a long time ago
	UPDATED(100); // Schedule recently successfully updated

	public static final Parcelable.Creator<ScheduleState> CREATOR = new Creator<ScheduleState>() {

		@Override
		public ScheduleState[] newArray(int size) {
			return new ScheduleState[size];
		}// newArray(int)

		@Override
		public ScheduleState createFromParcel(Parcel source) {
			int ordinal = source.readInt();
			return ScheduleState.getState(ordinal);
		}// createFromParcel(Parcel)

	};

	protected int weight;

	private ScheduleState(int weight) {
		this.weight = weight;
	}// ScheduleState(int)

	public static ScheduleState getState(int ordinal) {
		return ScheduleState.values()[ordinal];
	}// getState(int)

	public int getWeight() {
		return this.weight;
	}// getWeight()

	public boolean isUpdating() {
		switch (this) {
		case NOT_UPDATED:
		case OTHER:
		case UPDATED:
			return false;
		default:
		}// switch
		return true;
	}// if

	@Override
	public int describeContents() {
		return 0;
	}// describeContents()

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(this.ordinal());
	}// writeToParcel(Parcel, int)

}// enum ScheduleState